<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/6 12:21
 */

namespace module\ai\library\channel\platform;

use module\ai\library\channel\abstract\Platform;
use mof\Model;

class XunfeiPlatform extends Platform
{
    protected string $regUrl = 'https://www.xfyun.cn/';

    public static function getName(): string
    {
        return '讯飞星火';
    }

    public static function getFlag(): string
    {
        return 'xunfei';
    }


    public static function models(): array
    {
        return [
            'lite'        => 'Spark Lite (免费)',
            'generalv3'   => 'Spark Pro',
            'pro-128k'    => 'Spark Pro-128K',
            'generalv3.5' => 'Spark Max',
            'max-32k'     => 'Spark Max-32K',
            '4.0Ultra'    => 'Spark Ultra'
        ];
    }

    public function getConfigForm(Model $model = null): array
    {
        return [
            ...parent::getConfigForm($model),
            [
                "label" => "temperature",
                "prop"  => "config.temperature",
                "value" => $model['config']['temperature'] ?? '',
                "intro" => "核采样阈值，用于决定结果随机性，取值越高随机性越强，" .
                    "即相同的问题得到的不同答案的可能性越高。取值范围[0，1]，默认为0.5",
                "tip"   => "随机性"
            ],
            [
                "label" => "max_tokens",
                "prop"  => "config.max_tokens",
                "value" => $model['config']['max_tokens'] ?? '',
                "intro" => "1tokens 约等于1.5个中文汉字或者 0.8个英文单词",
                "tip"   => "回复长度限制"
            ],
            [
                "label" => "top-k",
                "prop"  => "config.top_k",
                "value" => $model['config']['top_k'] ?? '',
                "intro" => "平衡生成文本的质量和多样性，较小的 k 值会减少随机性，使得输出更加稳定；" .
                    "而较大的 k 值会增加随机性，产生更多新颖的输出。取值范围[1, 6]，默认为4",
                "tip"   => "灵活度"
            ],
        ];
    }

    public function getKeyColumns(): array
    {
        return [
            'appid'      => [
                'label'      => 'APPID',
                'table_hide' => true
            ],
            'secret_id'  => [
                'label'  => 'SecretId',
                'secret' => true,
            ],
            'secret_key' => [
                'label'      => 'SecretKey',
                'table_hide' => true,
                'secret'     => true,
            ]
        ];
    }
}